package com.atguigu.spzx.cloud.order.controller;

import com.atguigu.spzx.cloud.order.config.PatternProperties;
import com.atguigu.spzx.cloud.order.entity.Order;
import com.atguigu.spzx.cloud.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/api/order")
//@RefreshScope //热更新
@EnableConfigurationProperties({PatternProperties.class}) //让指定的类生效
public class OrderController {

    @Autowired
    OrderService orderService;

    /*
    datetime:
      format: yyyy-MM-dd
     */
    //@Value("${datetime.format}")
    // String format;

    @Autowired
    PatternProperties patternProperties;

    @GetMapping("/findOrderByOrderId/{id}")
    public Order findOrderByOrderId(@PathVariable("id") Long orderId){
//        System.out.println("format = " + format);
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
//        String dateFormat = simpleDateFormat.format(new Date());
//        System.out.println("dateFormat = " + dateFormat);

        System.out.println("patternProperties = " + patternProperties);
        
        Order order = orderService.findOrderByOrderId(orderId);
        return order;
    }
}
